package com.hhf.rpc.core.registry;

import com.hhf.rpc.core.model.ServiceMetaInfo;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author hhf
 * @Date 2024/10/18
 * @Description 注册中心服务本地缓存
 */
public class RegistryServiceCache {

    /**
     * 服务缓存
     */
    private Map<String,List<ServiceMetaInfo>> serviceCache = new ConcurrentHashMap<>();

    /**
     * 写缓存
     * @param serviceKey
     * @param newServiceCache
     */
    public void writeCache(String serviceKey,List<ServiceMetaInfo> newServiceCache){
        serviceCache.put(serviceKey,newServiceCache);
    }

    /**
     * 读缓存
     * @param serviceKey
     * @return
     */
    public List<ServiceMetaInfo> readCache(String serviceKey){
        return serviceCache.get(serviceKey);
    }

    /**
     * 清空缓存
     * @param serviceKey
     */
    public void clearCache(String serviceKey){
        serviceCache.remove(serviceKey);
    }





}
